/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hj7final;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;

/**
 *
 * ALGORITMOS Y ESTRUCTURA DE DATOS
 * HOJA DE TRABAJO 7 
 * YUCELY BEB 12537
 * VICTOR FUENTES 12298
 */



public class DriverGui extends JPanel{
    //atributos
    
    String cadena;
    
    private JLabel lInfoGeneral;
    
    private JButton bAgregar;
    
    private JTextField tfCuadro;
    
    private JTextPane tpInfo=new JTextPane();
    
    private JScrollPane scroll=new JScrollPane();
            
    HuffmanTree arbol=new HuffmanTree();
    
    public DriverGui(HuffmanTree arboll){
        arbol=arboll;
        lInfoGeneral=new JLabel("Ingrese la cadena");
        bAgregar=new JButton("Analizar");
        tfCuadro=new JTextField("",40);
        
        tpInfo.setSize(50, 50);
        tpInfo.setBackground(Color.red);
        tpInfo.enable(false);
        
        scroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
        scroll.setPreferredSize( new Dimension( 50, 50 ) );
        scroll.getViewport().add(tpInfo);
        
        ButtonListener listener=new ButtonListener();
        bAgregar.addActionListener(listener);
        
        TempListener cuadro=new TempListener();
        tfCuadro.addActionListener(cuadro);
        
        tpInfo.setText("esperando cadena...");
        
        
        add(lInfoGeneral);
        add(tfCuadro);
        add(tpInfo);
        add(bAgregar);
        
        setPreferredSize(new Dimension (600,300));
    }
    
    //eventos
    private class ButtonListener implements ActionListener{
        public void actionPerformed(ActionEvent boton){
            if(boton.getSource()==bAgregar){
                cadena=tfCuadro.getText();
                arbol.procesar(cadena);
                tpInfo.setText(arbol.toString());
                //System.out.println(arbol.toString());
                
                cadena="";
            }
        }
    }
    
    private class TempListener implements ActionListener{
        public void actionPerformed(ActionEvent cuadro){
            try{
               cadena=tfCuadro.getText(); 
            }catch(Exception e){
                
            }
        }
    }
    
}
